using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;


namespace Pong_Xvna
{
    /// <summary>
    /// This is a game component that implements IUpdateable.
    /// </summary>
    public class Pad : Sprite
    {
        Input input;
        int index;
        int point = 0;

        float accel = 2f;

        public int Point
        {
            get { return point; }
            set { point = value; }
        }
        public Pad(Game game, Vector2 pos, Vector2 velo, int index)
            : base(game, pos, velo)
        {
            this.index = index;

            nTexture2D = 1;
            iTexture2D = 0;
            texture = new Texture2D[nTexture2D];
            for (int i = 0; i < nTexture2D; i++)
                texture[i] = Game.Content.Load<Texture2D>("pad");
            input = (Input)Game.Services.GetService(typeof(Input));
        }
        

        public override void Initialize()
        {
            // TODO: Add your initialization code here

            base.Initialize();
        }
        public override void Update(GameTime gameTime)
        {
            if (index == 1 ? input.Press(Keys.Up) : input.Press(Keys.W))
                velocity.Y -= accel;
            else if (index == 1 ? input.Press(Keys.Down) : input.Press(Keys.S))
                velocity.Y += accel;

            velocity.Y = MathHelper.Clamp(velocity.Y, -7, 7);

            Vector2 lastPos = position;

            base.Update(gameTime);

            if (position.Y < 0 || position.Y > 500 - texture[0].Height)
                position = lastPos;
        }
        public override void Draw(GameTime gameTime)
        {
            base.Draw(gameTime);
        }
        public override Sprite Clone()
        {
            Sprite sp = new Pad(Game1, new Vector2(0, 300), Vector2.Zero, 0);
            return sp;
        }

    }
}